﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace BambolettaDB
{
    public class CustomerVM: BaseVM, IEditableObject
    {
        #region Properties and Methods
        private long _ID = -1;
        public long ID
        {
            get { return _ID; }
            set { _ID = value; NotifyPropertyChanged("ID"); }
        }

        private StringItemVM _Status = new StringItemVM();
        public StringItemVM Status
        {
            get { return _Status; }
            set { _Status = value; NotifyPropertyChanged("Status"); }
        }

        private string _Email = "";
        public string Email
        {
            get { return _Email; }
            set { _Email = value; NotifyPropertyChanged("Email"); }
        }

        private string _Name = "";
        public string Name
        {
            get { return _Name; }
            set { _Name = value; NotifyPropertyChanged("Name"); }
        }

        private StringItemVM _Location = new StringItemVM();
        public StringItemVM Location
        {
            get { return _Location; }
            set { _Location = value; NotifyPropertyChanged("Location"); }
        }

        #endregion

        #region Constructor
        public CustomerVM()
        {
            if (!App.IsInDesignMode)
            {
                Status = DBCommands.GetStatus()[0];
            }
        }
        #endregion

        #region Public methods
        public void Copy(CustomerVM from)
        {
            ID = from.ID;
            Status = from.Status;
            Email = from.Email;
            Name = from.Name;
            Location = from.Location;
        }

        public override bool Equals(object obj)
        {
            CustomerVM compareTo = obj as CustomerVM;
            if (compareTo != null)
            {
                if (ID != -1 && compareTo.ID != -1)
                    return ID == compareTo.ID;
            }

            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return (int)ID;
        }
        #endregion

        public void BeginEdit()
        {
        }

        public void CancelEdit()
        {
        }

        public void EndEdit()
        {
            if (ID != -1)
                DBCommands.UpdateCustomer(this);
        }
    }
}
